/*
 * @Author: your name
 * @Date: 2021-08-26 15:56:56
 * @LastEditTime: 2021-09-06 09:57:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /index/src/ys/cesium/Point.js
 */
import * as Cesium from "cesium"

/**
 * @description: 点位显示相关的函数，实体设置
 * @param {*} viewer
 * @param {*} layerName
 * @return {*}
 */
function PointLayer(viewer, layerName) {
  this.viewer = viewer;
  this.layerName = layerName;
  this.pointArr = [];
  this.pointsParent = viewer.entities.getById(this.layerName);
  if (!this.pointsParent) {
    this.pointsParent = viewer.entities.add(
      new Cesium.Entity({
        id: this.layerName,
      })
    );
  } else {
    this.pointsParent.show = true;
  }
}

/**
 * @description: 添加普通点位信息
 * @param {*}
 * @return {*}
 */
PointLayer.prototype.addPoint = function () {
  // position, pointConfig, description
  let point = this.viewer.entities.add({
    parent: this.pointsParent,
    position: Cesium.Cartesian3.fromDegrees(110.686335, 25.617108, 2000),
    description: "描述信息",
    point: {
      pixelSize: 10,
      color: Cesium.Color.RED,
      outlineColor: Cesium.Color.RED,
      outlineWidth: 5,
    },
    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  });
  this.pointArr.push(point);
  console.log("添加点");
};

/**
 * @description: 显隐状态切换
 * @param {*}
 * @return {*}
 */
PointLayer.prototype.setVisible = function() {
  this.pointsParent.show = !this.pointsParent.show;
};

export default PointLayer;